

package com.hazelcast.internal.locksupport;

import com.hazelcast.internal.locksupport.operations.*;
import com.hazelcast.internal.serialization.DataSerializerHook;
import com.hazelcast.internal.serialization.impl.FactoryIdHelper;
import com.hazelcast.nio.serialization.DataSerializableFactory;

import static com.hazelcast.internal.serialization.impl.FactoryIdHelper.LOCK_DS_FACTORY;
import static com.hazelcast.internal.serialization.impl.FactoryIdHelper.LOCK_DS_FACTORY_ID;

public final class LockDataSerializerHook implements DataSerializerHook {

    public static final int F_ID = FactoryIdHelper.getFactoryId(LOCK_DS_FACTORY, LOCK_DS_FACTORY_ID);

    public static final int LOCK_RESOURCE = 0;
    public static final int LOCK_STORE = 1;
    public static final int IS_LOCKED = 9;
    public static final int LOCK_BACKUP = 10;
    public static final int LOCK = 11;
    public static final int LOCK_REPLICATION = 12;
    public static final int UNLOCK_BACKUP = 15;
    public static final int UNLOCK = 16;
    public static final int UNLOCK_IF_LEASE_EXPIRED = 17;


    @Override
    public int getFactoryId() {
        return F_ID;
    }

    @Override
    public DataSerializableFactory createFactory() {
        return typeId -> switch (typeId) {
            case IS_LOCKED -> new IsLockedOperation();
            case LOCK -> new LockOperation();
            case LOCK_BACKUP -> new LockBackupOperation();
            case LOCK_REPLICATION -> new LockReplicationOperation();
            case UNLOCK_BACKUP -> new UnlockBackupOperation();
            case UNLOCK -> new UnlockOperation();
            case LOCK_STORE -> new LockStoreImpl();
            case LOCK_RESOURCE -> new LockResourceImpl();
            case UNLOCK_IF_LEASE_EXPIRED -> new UnlockIfLeaseExpiredOperation();
            default -> null;
        };
    }
}
